﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using NHibernate.Mapping.Attributes;
using NHibernate;
using NHibernate.Criterion;
namespace Service
{
    [Class(Table = "m_CustomerCard_Customer", Name = "CCCustomer")]
    [Serializable]
    public class CCCustomer
    {
        [Id(0, Column = "ID_Customer", Type = "int", Name = "ID_Customer")]
        [Generator(1, Class = "identity")]
        public virtual int ID_Customer { get; protected set; }

        [Property(Name = "ID_Company", Column = "ID_Company", Type = "int")]
        public virtual int  ID_Company { get; set; }

        [Property(Name = "Level", Column = "Level", Type = "int")]
        public virtual int Level { get; set; }

        [Property(Name = "ID_Parent", Column = "ID_Parent", Type = "int")]
        public virtual int ID_Parent { get; set; }

        [Property(Name = "CreateTimeStamp", Column = "CreateTimeStamp", Type = "DateTime")]
        public virtual DateTime CreateTimeStamp { get; set; }

        [Property(Name = "ID_File", Column = "ID_File", Type = "int")]
        public virtual int ID_File { get; set; }

        //[Bag(1, Inverse = false, Lazy = CollectionLazy.False, Table = "m_CustomerCard_Address", Cascade = "all-delete-orphan")]
        //[Key(2, Column = "ID_Customer")]
        //[OneToMany(3, Class = "CustomerCard.CCAddress", ClassType = typeof(CCAddress))]
        //public virtual IList<CCAddress> Address { get; set; }

        //[Bag(1, Inverse = false, Lazy = CollectionLazy.True, Table = "m_CustomerCard_Customer2User", Cascade = "none")]
        //[Key(2, Column = "ID_Customer")]
        //[ManyToMany(3, Column = "ID_User", ClassType = typeof(SaasUser))]
        //public virtual IList<SaasUser> Users { get; set; }

        [Property(Name = "ID_AAddress", Column = "ID_AAddress", Type = "int")]
        public virtual int ID_AAddress { get; set; }

        [Property(Name = "ID_Usr", Column = "ID_Usr", Type = "int")]
        public virtual int ID_Usr { get; set; }

        //[Bag(1, Inverse = false, Lazy = CollectionLazy.False, Table = "m_customercard_customer_additional_accounts", Cascade = "all-delete-orphan")]
        //[Key(2, Column = "ID_Customer")]
        //[OneToMany(3, Class = "CustomerCard.CCustomerAdditionalAccount", ClassType = typeof(CCustomerAdditionalAccount))]
        //public virtual IList<CCustomerAdditionalAccount> AdditionalAccounts { get; set; }
    }

   
    [Class(Table = "m_CustomerCard_Address", Name = "CCAddress")]
    [Serializable]
    public class CCAddress
    {
        public CCAddress()
        {
        }

        [Id(0, Column = "ID_Address", Type = "int", Name = "ID_Address")]
        [Generator(1, Class = "identity")]
        public virtual int ID_Address { get; protected set; }

        [Property(Name = "ID_Customer", Column = "ID_Customer", Type = "int")]
        public virtual int ID_Customer { get; set; }

        [Property(Name = "AddressIndex", Column = "AddressIndex", Type = "int")]
        public virtual int AddressIndex { get; set; }

        [Property(Name = "Region", Column = "Region", Type = "String")]
        public virtual string Region { get; set; }

        [Property(Name = "Area", Column = "Area", Type = "String")]
        public virtual string Area { get; set; }

        [Property(Name = "City", Column = "City", Type = "String")]
        public virtual string City { get; set; }

        [Property(Name = "Street", Column = "Street", Type = "String")]
        public virtual string Street { get; set; }

        [Property(Name = "Korpus", Column = "Korpus", Type = "String")]
        public virtual string Korpus { get; set; }

        [Property(Name = "HouseNumber", Column = "HouseNumber", Type = "String")]
        public virtual string HouseNumber { get; set; }

        [Property(Name = "Flat", Column = "Flat", Type = "String")]
        public virtual string Flat { get; set; }

        [Property(Name="ID_AddressType", Column = "ID_AddressType",Type="int")]
        public virtual int ID_AddressType { get; set; }

        [Property(Name = "HouseType", Column = "HouseType", Type = "int")]
        public virtual int HouseType { get; set; }

        [Property(Name = "KorpusType", Column = "KorpusType", Type = "int")]
        public virtual int KorpusType { get; set; }

        [Property(Name = "FlatType", Column = "FlatType", Type = "int")]
        public virtual int FlatType { get; set; }
    }

    [Class(Table = "m_CustomerCard_Phone", Name = "CCPhone")]
    [Serializable]
    public class CCPhone
    {
        public CCPhone()
        {
        }

        public virtual void ResetID()
        {
            ID_Phone = 0;
        }

        [Id(0, Column = "ID_Phone", Type = "int", Name = "ID_Phone")]
        [Generator(1, Class = "identity")]
        public virtual int ID_Phone { get; protected set; }

        [Property(Name = "ID_Customer", Column = "ID_Customer", Type = "int")]
        public virtual int ID_Customer { get; set; }

        [Property(Name = "Number", Column = "Number", Type = "long")]
        public virtual long Number { get; set; }

        [Property(Name = "Mask", Column = "Mask", Type = "String")]
        public virtual string Mask { get; set; }

        [Property(Name ="ID_PhoneType", Column = "ID_PhoneType",Type="int")]
        public virtual int ID_PhoneType { get; set; }
    }

    [JoinedSubclass(1, Name = "CCPerson", ExtendsType = typeof(CCCustomer), Table = "m_CustomerCard_Person")]
    [Key(2, Column = "ID_Customer")]
    [Serializable]
    public class CCPerson : CCCustomer
    {
        //[Bag(1, Inverse = false, Lazy = CollectionLazy.False, Table = "m_CustomerCard_Phone", Cascade = "all-delete-orphan")]
        //[Key(2, Column = "ID_Customer")]
        //[OneToMany(3, Class = "CustomerCard.CCPhone", ClassType = typeof(CCPhone))]
        //public virtual IList<CCPhone> Phone { get; set; }

        //[Bag(1, Inverse = false, Lazy = CollectionLazy.False, Table = "m_CustomerCard_SocialNetwork", Cascade = "all-delete-orphan")]
        //[Key(2, Column = "ID_Customer")]
        //[OneToMany(3, Class = "CustomerCard.CCSocialNetwork", ClassType = typeof(CCSocialNetwork))]
        //public virtual IList<CCSocialNetwork> SocialNetwork { get; set; }

        public CCPerson()
        {
        }
        public CCPerson(int ID_Customer)
        {
            this.ID_Customer = ID_Customer;
        }

        [Property(Name = "Surname", Column = "Surname", Type = "String")]
        public virtual string Surname { get; set; }

        [Property(Name = "Name", Column = "Name", Type = "String")]
        public virtual string Name { get; set; }

        [Property(Name = "Patroname", Column = "Patroname", Type = "String")]
        public virtual string Patroname { get; set; }

        [Property(Name = "Birthday", Column = "Birthday", Type = "DateTime")]
        public virtual DateTime Birthday { get; set; }

        //[ScorableField(UiName = "Возраст")]
        /*public virtual int Age
        {
            get
            {
                // http://stackoverflow.com/questions/9/how-do-i-calculate-someones-age
                DateTime now = DateTime.Today;
                int age = now.Year - Birthday.Year;
                if (Birthday > now.AddYears(-age)) age--;
                return age;
            }
        }*/

        [Property(Name = "BirthdayPlace", Column = "BirthdayPlace", Type = "String")]
        public virtual string BirthdayPlace { get; set; }

        [Property(Name = "PassportNum", Column = "PassportNum", Type = "long")]
        public virtual long PassportNum { get; set; }

        [Property(Name = "BirthdayRegion", Column = "BirthdayRegion", Type = "String")]
        public virtual string BirthdayRegion { get; set; }

        [Property(Name = "BirthdayDistrict", Column = "BirthdayDistrict", Type = "String")]
        public virtual string BirthdayDistrict { get; set; }

        [Property(Name = "BirthdayCity", Column = "BirthdayCity", Type = "String")]
        public virtual string BirthdayCity { get; set; }

        [Property(Name = "PassportPlace", Column = "PassportPlace", Type = "String")]
        public virtual string PassportPlace { get; set; }

        [Property(Name = "PassportDate", Column = "PassportDate", Type = "DateTime")]
        public virtual DateTime PassportDate { get; set; }

        //[Property(Name = "INN", Column = "INN", Type = "String")]
        //public virtual string INN { get; set; }

        //[ScorableField(UiName = "Семейное положение")]
        
        [ManyToOne(Class = "CCMaritalStatus", ClassType = typeof(CCMaritalStatus), Column = "ID_MaritalStatus")]
        public virtual CCMaritalStatus MaritalStatus { get; set; }

        
        [ManyToOne(Class = "CCEducation", ClassType = typeof(CCEducation), Column = "ID_Education")]
        public virtual CCEducation Education { get; set; }

        [Property(Name = "ID_ParentRelation", Column = "ID_ParentRelation", Type = "int")]
        public virtual int ID_ParentRelation { get; set; }

        //[Property(Name = "NotPromising", Column = "NotPromising", Type = "bool")]
        //public virtual bool NotPromising { get; set; }

        //[Property(Name = "NotPromisingDate", Column = "NotPromisingDate", Type = "DateTime")]
        //public virtual DateTime NotPromisingDate { get; set; }

        //[Property(Name = "NotPromisingUser", Column = "NotPromisingUser", Type = "int")]
        //public virtual int NotPromisingUser { get; set; }

        [Property(Name = "ID_Gender", Column = "ID_Gender", Type = "int")]
        public virtual int ID_Gender { get; set; }

        //[ScorableField(UiName = "Пол")]
        //[Property(Name="ID_Gender", Column = "ID_Gender",Type="int")]
        //public virtual int Gender { get; protected set; }

        [Property(Name = "Email", Column = "Email", Type = "String")]
        public virtual string Email { get; set; }

        [Property(Name = "Post", Column = "Post", Type = "String")]
        public virtual string Post { get; set; }

        [Property(Name = "IsReferee", Column = "IsReferee", Type = "bool")]
        public virtual bool IsReferee { get; set; }

        [Property(Name = "IsClosePerson", Column = "IsClosePerson", Type = "bool")]
        public virtual bool IsClosePerson { get; set; }

        [Property(Name = "Archived", Column = "Archived", Type = "bool")]
        public virtual bool Archived { get; set; }

    }

    [Class(Table = "m_CustomerCard_MaritalStatus", Name = "CCMaritalStatus")]
    public class CCMaritalStatus 
    {
        public CCMaritalStatus()
        {
        }
        public CCMaritalStatus(int id, string name)
        {
            ID_MaritalStatus = -1;
            Name = name;
        }

        [Id(0, Column = "ID_MaritalStatus", Type = "int", Name = "ID_MaritalStatus")]
        [Generator(1, Class = "increment")]
        public virtual int ID_MaritalStatus { get; protected set; }

        [Property(Name = "Name", Column = "Name", Type = "String")]
        public virtual string Name { get; set; }
    }

    [Class(Table = "m_CustomerCard_Education", Name = "CCEducation")]
    public class CCEducation 
    {
        public CCEducation()
        {
        }
        public CCEducation(int id, string name)
        {
            ID_Education = id;
            Name = name;
        }
                
        [Id(0, Column = "ID_Education", Type = "int", Name = "ID_Education")]
        [Generator(1, Class = "increment")]
        public virtual int ID_Education { get; protected set; }

        [Property(Name = "Name", Column = "Name", Type = "String")]
        public virtual string Name { get; set; }
    }

    [Class(Table = "m_credit_seconddocs", Name = "CreditSecondDoc")]
    [Serializable]
    public class CreditSecondDoc
    {
        public CreditSecondDoc()
        {
        }

        [Id(0, Column = "ID_SecondDoc", Type = "int", Name = "ID_SecondDoc")]
        [Generator(1, Class = "identity")]
        public virtual int ID_SecondDoc { get; protected set; }

        [Property(Name = "ID_Customer", Column = "ID_Customer", Type = "int")]
        public virtual int ID_Customer { get; set; }

        [Property(Name = "Number", Column = "Number", Type = "string")]
        public virtual string Number { get; set; }

        [Property(Name = "ID_Customerfile", Column = "ID_Customerfile", Type = "int")]
        public virtual int ID_Customerfile { get; set; }

        [Property(Name="ID_SecondDocType", Column = "ID_SecondDocType",Type="int")]
        public virtual int ID_SecondDocType { get; set; }
    }

    [JoinedSubclass(1, Name = "CreditPerson", ExtendsType = typeof(CCPerson), Table = "m_Credit_Person")]
    [Key(2, Column = "ID_Customer")]
    [Serializable]
    public class CreditPerson : CCPerson
    {

        [Property(Name = "SecondDoc", Column = "SecondDoc", Type = "String")]
        public virtual string SecondDoc { get; set; }

        [Property(Name = "WorkPlace", Column = "WorkPlace", Type = "String")]
        public virtual string WorkPlace { get; set; }

        [Property(Name = "WorkPost", Column = "WorkPost", Type = "String")]
        public virtual string WorkPost { get; set; }

        //[ScorableField(UiName = "Стаж работы (месяцев)")]
        [Property(Name = "WorkTime", Column = "WorkTime", Type = "decimal")]
        public virtual decimal WorkTime { get; set; }

        [Property(Name = "AvgIncome", Column = "AvgIncome", Type = "decimal")]
        public virtual decimal AvgIncome { get; set; }

        [Property(Name = "AvgOutgo", Column = "AvgOutgo", Type = "decimal")]
        public virtual decimal AvgOutgo { get; set; }

        [Property(Name = "SalaryDate", Column = "SalaryDate", Type = "int")]
        public virtual int SalaryDate { get; set; }

        [Property(Name = "PrepaymentDate", Column = "PrepaymentDate", Type = "int")]
        public virtual int PrepaymentDate { get; set; }

        [Property(Name = "AdditionalIncome", Column = "AdditionalIncome", Type = "decimal")]
        public virtual decimal AdditionalIncome { get; set; }

        [Property(Name = "HasDependents", Column = "HasDependents", Type = "bool")]
        public virtual bool HasDependents { get; set; }

        //[ScorableField(UiName = "Иждивенцы")]
        [Property(Name = "Dependents", Column = "Dependents", Type = "int")]
        public virtual int Dependents { get; set; }

        [Property(Name = "Crime", Column = "Crime", Type = "String")]
        public virtual string Crime { get; set; }

        [Property(Name = "HasCrime", Column = "HasCrime", Type = "bool")]
        public virtual bool HasCrime { get; set; }

        //[ScorableField(UiName = "Уголовная ответственность")]
        //[ManyToOne(Class = "Credit.HasCrimeDigest", ClassType = typeof(HasCrimeDigest), Column = "HasCrime", ForeignKey = "ID_HasCrimeDigest", Insert = false, Update = false)]
        //public virtual HasCrimeDigest CrimeDigest { get; protected set; }

        [Property(Name = "Avto", Column = "Avto", Type = "String")]
        public virtual string Avto { get; set; }

        [Property(Name = "HasAvto", Column = "HasAvto", Type = "bool")]
        public virtual bool HasAvto { get; set; }

        //[ScorableField(UiName = "Авто")]
        //[ManyToOne(Class = "Credit.HasAutoDigest", ClassType = typeof(HasAutoDigest), Column = "HasAvto", ForeignKey = "ID_HasAutoDigest", Insert = false, Update = false)]
        //public virtual HasAutoDigest AutoDigest { get; protected set; }

        [Property(Name = "Home", Column = "Home", Type = "String")]
        public virtual string Home { get; set; }

        [Property(Name = "HasHome", Column = "HasHome", Type = "bool")]
        public virtual bool HasHome { get; set; }

        //[ScorableField(UiName = "Квартира")]
        //[ManyToOne(Class = "Credit.HasFlatDigest", ClassType = typeof(HasFlatDigest), Column = "HasHome", ForeignKey = "ID_HasFlatDigest", Insert = false, Update = false)]
        //public virtual HasFlatDigest FlatDigest { get; protected set; }

        [Property(Name = "HasWork", Column = "HasWork", Type = "int")]
        public virtual int HasWork { get; set; }

        [Property(Name = "ID_NoWorkType", Column = "ID_NoWorkType", Type = "int")]
        public virtual int ID_NoWorkType { get; set; }

        [Property(Name = "WorkPlaceRegion", Column = "WorkPlaceRegion", Type = "String")]
        public virtual string WorkPlaceRegion { get; set; }

        [Property(Name = "WorkPlaceCity", Column = "WorkPlaceCity", Type = "String")]
        public virtual string WorkPlaceCity { get; set; }

        [Property(Name = "WorkPlaceStreet", Column = "WorkPlaceStreet", Type = "String")]
        public virtual string WorkPlaceStreet { get; set; }

        [Property(Name = "WorkPlaceHouseNumber", Column = "WorkPlaceHouseNumber", Type = "String")]
        public virtual string WorkPlaceHouseNumber { get; set; }

        [Property(Name = "ID_SecondDocType", Column = "ID_SecondDocType", Type = "int")]
        public virtual int ID_SecondDocType { get; set; }

        [Property(Name = "SecondDocNumber", Column = "SecondDocNumber", Type = "String")]
        public virtual string SecondDocNumber { get; set; }

        [Property(Name = "AvtoMark", Column = "AvtoMark", Type = "String")]
        public virtual string AvtoMark { get; set; }

        [Property(Name = "AvtoModel", Column = "AvtoModel", Type = "String")]
        public virtual string AvtoModel { get; set; }

        [Property(Name = "AvtoYear", Column = "AvtoYear", Type = "String")]
        public virtual string AvtoYear { get; set; }

        [Property(Name = "AvtoNumber", Column = "AvtoNumber", Type = "String")]
        public virtual string AvtoNumber { get; set; }

        [Property(Name = "CrimeArticle", Column = "CrimeArticle", Type = "String")]
        public virtual string CrimeArticle { get; set; }

        [Property(Name = "CrimeDescription", Column = "CrimeDescription", Type = "String")]
        public virtual string CrimeDescription { get; set; }

        [Property(Name = "AvtoProperty", Column = "AvtoProperty", Type = "decimal")]
        public virtual decimal AvtoProperty { get; set; }

        [Property(Name = "HomeProperty", Column = "HomeProperty", Type = "decimal")]
        public virtual decimal HomeProperty { get; set; }


        [Property(Name = "HasLand", Column = "HasLand", Type = "bool")]
        public virtual bool HasLand { get; set; }

        [Property(Name = "ID_LandType", Column = "ID_LandType", Type = "int")]
        public virtual int ID_LandType { get; set; }

        [Property(Name = "LandProperty", Column = "LandProperty", Type = "decimal")]
        public virtual decimal LandProperty { get; set; }


        [Property(Name = "HomeRegion", Column = "HomeRegion", Type = "String")]
        public virtual string HomeRegion { get; set; }

        [Property(Name = "HomeCity", Column = "HomeCity", Type = "String")]
        public virtual string HomeCity { get; set; }

        [Property(Name = "HomeStreet", Column = "HomeStreet", Type = "String")]
        public virtual string HomeStreet { get; set; }

        [Property(Name = "HomeHouseNumber", Column = "HomeHouseNumber", Type = "String")]
        public virtual string HomeHouseNumber { get; set; }

        [Property(Name = "HomeKorpus", Column = "HomeKorpus", Type = "String")]
        public virtual string HomeKorpus { get; set; }

        [Property(Name = "HomeFlat", Column = "HomeFlat", Type = "String")]
        public virtual string HomeFlat { get; set; }

        [Property(Name = "BirthdaySmsDate", Column = "BirthdaySmsDate", Type = "DateTime")]
        public virtual DateTime BirthdaySmsDate { get; set; }

        [Property(Name = "IsImport", Column = "IsImport", Type = "bool")]
        public virtual bool IsImport { get; set; }

        [Property(Name = "Scope", Column = "Scope", Type = "String")]
        public virtual string Scope { get; set; }

        [Property(Name = "NoAddress", Column = "NoAddress", Type = "bool")]
        public virtual bool NoAddress { get; set; }

        [Property(Name = "WorkLink", Column = "WorkLink", Type = "String")]
        public virtual string WorkLink { get; set; }
    }

    [Class(Table = "m_Credit_PaymentRow", Name = "PaymentRow")]
    [Serializable]
    public class PaymentRow
    {
        public PaymentRow()
        {
        }

        [Id(0, Column = "ID_PaymentRow", Type = "int", Name = "ID_PaymentRow")]
        [Generator(1, Class = "increment")]//[Generator(1, Class = "identity")]
        public virtual int ID_PaymentRow { get; protected set; }

        [Property(Name = "ID_Deal", Column = "ID_Deal", Type = "int")]
        public virtual int ID_Deal { get; set; }

        [Property(Name = "RowDate", Column = "RowDate", Type = "DateTime")]
        public virtual DateTime RowDate { get; set; }

        [Property(Name = "CreditBodyBegin", Column = "CreditBodyBegin", Type = "decimal")]
        public virtual decimal CreditBodyBegin { get; set; }

        [Property(Name = "CreditPercentBegin", Column = "CreditPercentBegin", Type = "decimal")]
        public virtual decimal CreditPercentBegin { get; set; }

        [Property(Name = "PercentAcummSumBegin", Column = "PercentAcummSumBegin", Type = "decimal")]
        public virtual decimal PercentAcummSumBegin { get; set; }

        [Property(Name = "PlanAmount", Column = "PlanAmount", Type = "decimal")]
        public virtual decimal PlanAmount { get; set; }

        [Property(Name = "FactBody", Column = "FactBody", Type = "decimal")]
        public virtual decimal FactBody { get; set; }

        [Property(Name = "FactPercent", Column = "FactPercent", Type = "decimal")]
        public virtual decimal FactPercent { get; set; }

        [Property(Name = "FactAccumSum", Column = "FactAccumSum", Type = "decimal")]
        public virtual decimal FactAccumSum { get; set; }

        [Property(Name = "CreditBodyEnd", Column = "CreditBodyEnd", Type = "decimal")]
        public virtual decimal CreditBodyEnd { get; set; }

        [Property(Name = "CreditPercentEnd", Column = "CreditPercentEnd", Type = "decimal")]
        public virtual decimal CreditPercentEnd { get; set; }

        [Property(Name = "PaymentDif", Column = "PaymentDif", Type = "decimal")]
        public virtual decimal PaymentDif { get; set; }

        [Property(Name = "PaymentDelay", Column = "PaymentDelay", Type = "decimal")]
        public virtual decimal PaymentDelay { get; set; }

        [Property(Name = "DelayCount", Column = "DelayCount", Type = "int")]
        public virtual int DelayCount { get; set; }

        [Property(Name = "ID_Sms", Column = "ID_Sms", Type = "int")]
        public virtual int ID_Sms { get; set; }

        public virtual decimal FromPayment { get; set; }

        [Property(Name = "PaymentDelayHistory", Column = "PaymentDelayHistory", Type = "decimal")]
        public virtual decimal PaymentDelayHistory { get; set; }

        [Property(Name = "DelayCountHistory", Column = "DelayCountHistory", Type = "int")]
        public virtual int DelayCountHistory { get; set; }
    }

    [Class(Table = "m_CustomerCard_Document", Name = "CCDocument")]
    public class CCDocument
    {
        public CCDocument()
        {
        }

        [Id(0, Column = "ID_Document", Type = "int", Name = "ID_Document")]
        [Generator(1, Class = "identity")]
        public virtual int ID_Document { get; protected set; }

        [Property(Name = "ID_Customer", Column = "ID_Customer", Type = "int")]
        public virtual int ID_Customer { get; set; }

        [Property(Name = "ID_Deal", Column = "ID_Deal", Type = "int")]
        public virtual int ID_Deal { get; set; }

        [Property(Name = "Number", Column = "Number", Type = "int")]
        public virtual int Number { get; set; }

        [Property(Name = "Name", Column = "Name", Type = "string")]
        public virtual string Name { get; set; }

        [Property(Name = "Comment", Column = "Comment", Type = "String")]
        public virtual string Comment { get; set; }

        [Property(Name = "DocumentDate", Column = "DocumentDate", Type = "Date")]
        public virtual DateTime DocumentDate { get; set; }

        [Property(Name = "ID_DocumentType", Column = "ID_DocumentType", Type = "int")]
        public virtual int ID_DocumentType { get; set; }

        [ManyToOne(Class = "CCDeal", ClassType = typeof(CCDeal), Column = "ID_Deal", Insert = false, Update = false)]
        public virtual CCDeal Deal { get; protected set; }

        //[Bag(1, Inverse = false, Lazy = CollectionLazy.False, Table = "m_CustomerCard_DocumentFile", Cascade = "none")]
        //[Key(2, Column = "ID_Document")]
        //[OneToMany(3, Class = "CustomerCard.CCDocumentFile", ClassType = typeof(CCDocumentFile))]
        //public virtual IList<CCDocumentFile> files { get; set; }

        [Property(Name = "ID_User", Column = "ID_User", Type = "int")]
        public virtual int ID_User { get; set; }

        [Property(Name = "ID_AffiliateAddress", Column = "ID_AffiliateAddress", Type = "int")]
        public virtual int ID_AffiliateAddress { get; set; }
    }

 

    [Class(Table = "m_CustomerCard_DealStatus", Name = "CCDealStatus")]
    [Serializable]
    public class CCDealStatus
    {
        public CCDealStatus()
        {
        }

        [Id(0, Column = "ID_DealStatus", Type = "int", Name = "ID_DealStatus")]
        [Generator(1, Class = "increment")]
        public virtual int ID_DealStatus { get; protected set; }

        [Property(Name = "Name", Column = "Name", Type = "String")]
        public virtual string Name { get; set; }
    }

    [Class(Table = "m_CustomerCard_Deal", Name = "CCDeal")]
    [Serializable]
    public class CCDeal
    {
        public CCDeal()
        {
        }

        public CCDeal(int id, DateTime StartDate, decimal Amount)
        {
            ID_Deal = -1;
            this.StartDate = StartDate;
            this.Amount = Amount;
        }

        [Id(0, Column = "ID_Deal", Type = "int", Name = "ID_Deal")]
        [Generator(1, Class = "identity")]
        public virtual int ID_Deal { get; protected set; }

        [Property(Name = "ID_Customer", Column = "ID_Customer", Type = "int")]
        public virtual int ID_Customer { get; set; }

        [Property(Name = "ID_DealStatus", Column = "ID_DealStatus", Type = "int")]
        public virtual int ID_DealStatus { get; set; }

        [Property(Name = "Amount", Column = "Amount", Type = "decimal")]
        public virtual decimal Amount { get; set; }

        [Property(Name = "Percent", Column = "Percent", Type = "decimal")]
        public virtual decimal Percent { get; set; }

        [Property(Name = "PenaltyPercent", Column = "PenaltyPercent", Type = "decimal")]
        public virtual decimal PenaltyPercent { get; set; }

        [Property(Name = "AutoExtendDays", Column = "AutoExtendDays", Type = "int")]
        public virtual int AutoExtendDays { get; set; }

        [Property(Name = "Period", Column = "Period", Type = "int")]
        public virtual int Period { get; set; }

        [Property(Name = "ExtendDealDate", Column = "ExtendDealDate", Type = "DateTime")]
        public virtual DateTime ExtendDealDate { get; set; }

        [Property(Name = "StartDate", Column = "StartDate", Type = "DateTime")]
        public virtual DateTime StartDate { get; set; }

        [Property(Name = "EndDate", Column = "EndDate", Type = "DateTime")]
        public virtual DateTime EndDate { get; set; }

        [Property(Name = "CourtDate", Column = "CourtDate", Type = "DateTime")]
        public virtual DateTime CourtDate { get; set; }

        [Property(Name = "AmicableAgreementDate", Column = "AmicableAgreementDate", Type = "DateTime")]
        public virtual DateTime AmicableAgreementDate { get; set; }

        [Property(Name = "DebtRestructuringDate", Column = "DebtRestructuringDate", Type = "DateTime")]
        public virtual DateTime DebtRestructuringDate { get; set; }

        [Bag(1, Inverse = false, Lazy = CollectionLazy.False, Table = "m_CustomerCard_Payment", Cascade = "all-delete-orphan")]
        [Key(2, Column = "ID_Deal")]
        [OneToMany(3, Class = "CCPayment", ClassType = typeof(CCPayment))]
        public virtual IList<CCPayment> Payment { get; set; }

        // added 07.02.2012 for Amicable Agreement payments
        [Bag(1, Inverse = false, Lazy = CollectionLazy.False, Table = "m_CustomerCard_AmicableAgreement", Cascade = "all-delete-orphan")]
        [Key(2, Column = "ID_Deal")]
        [OneToMany(3, Class = "CCAAgreementPayment", ClassType = typeof(CCAAgreementPayment))]
        public virtual IList<CCAAgreementPayment> AAgreementPayment { get; set; }

        [Bag(1, Inverse = false, Lazy = CollectionLazy.False, Table = "m_customercard_debtrestructuring", Cascade = "all-delete-orphan")]
        [Key(2, Column = "ID_Deal")]
        [OneToMany(3, Class = "CCDebtRestructuring", ClassType = typeof(CCDebtRestructuring))]
        public virtual IList<CCDebtRestructuring> DebtRestructuring { get; set; }

        [ManyToOne(Class = "CCPerson", ClassType = typeof(CCPerson), Column = "ID_Customer", Insert = false, Update = false)]
        public virtual CCPerson Person { get; protected set; }

        [ManyToOne(Class = "CCDealStatus", ClassType = typeof(CCDealStatus), Column = "ID_DealStatus", Insert = false, Update = false)]
        public virtual CCDealStatus DealStatus { get; protected set; }

        [Bag(1, Inverse = false, Lazy = CollectionLazy.False, Table = "m_Credit_PaymentRow", Cascade = "none", OrderBy = "RowDate")]
        [Key(2, Column = "ID_Deal")]
        [OneToMany(3, Class = "PaymentRow", ClassType = typeof(PaymentRow))]
        public virtual IList<PaymentRow> paymentrow { get; set; }

        [Property(Name = "CreditAim", Column = "CreditAim", Type = "String")]
        public virtual string CreditAim { get; set; }

        [Property(Name = "SumReturnOrder", Column = "SumReturnOrder", Type = "decimal")]
        public virtual decimal SumReturnOrder { get; set; }

        [Property(Name = "SumPercentOrder", Column = "SumPercentOrder", Type = "decimal")]
        public virtual decimal SumPercentOrder { get; set; }

        [Property(Name = "EndDateOrder", Column = "EndDateOrder", Type = "DateTime")]
        public virtual DateTime EndDateOrder { get; set; }

        [Property(Name = "LastUpdate", Column = "LastUpdate", Type = "DateTime")]
        public virtual DateTime LastUpdate { get; set; }

        //[Bag(1, Inverse = false, Lazy = CollectionLazy.False, Table = "m_CustomerCard_Task", Cascade = "none")]
        //[Key(2, Column = "ID_Deal")]
        //[OneToMany(3, Class = "CustomerCard.CCTask", ClassType = typeof(CCTask))]
        //public virtual IList<CCTask> Task { get; set; }

        [Property(Name = "StopPercentDate", Column = "StopPercentDate", Type = "DateTime")]
        public virtual DateTime StopPercentDate { get; set; }

        [Property(Name = "ForgetCourtPayment", Column = "ForgetCourtPayment", Type = "bool")]
        public virtual bool ForgetCourtPayment { get; set; }

        [Property(Name = "ID_User", Column = "ID_User", Type = "int")]
        public virtual int ID_User { get; set; }

        [Property(Name = "ID_AffiliateAddress", Column = "ID_AffiliateAddress", Type = "int")]
        public virtual int ID_AffiliateAddress { get; set; }

        [Property(Name = "StopAutoPenalty", Column = "StopAutoPenalty", Type = "bool")]
        public virtual bool StopAutoPenalty { get; set; }
    }

    [Class(Table = "m_customercard_AmicableAgreement", Name = "CCAAgreementPayment")]
    [Serializable]
    public class CCAAgreementPayment
    {
        public CCAAgreementPayment()
        {
        }

        [Id(0, Column = "ID_AAgreementPayment", Type = "int", Name = "ID_AAgreementPayment")]
        [Generator(1, Class = "identity")]
        public virtual int ID_AAgreementPayment { get; protected set; }

        [Property(Name = "ID_Deal", Column = "ID_Deal", Type = "int")]
        public virtual int ID_Deal { get; set; }

        [Property(Name = "PlanDate", Column = "PlanDate", Type = "DateTime")]
        public virtual DateTime PlanDate { get; set; }
        /*
        [Property(Name = "FactDate", Column = "FactDate", Type = "DateTime")]
        public virtual DateTime FactDate { get; set; }
        */
        [Property(Name = "PlanAmount", Column = "PlanAmount", Type = "decimal")]
        public virtual decimal PlanAmount { get; set; }

        [Property(Name = "FactAmount", Column = "FactAmount", Type = "decimal")]
        public virtual decimal FactAmount { get; set; }

        [Property(Name = "FactDif", Column = "FactDif", Type = "decimal")]
        public virtual decimal FactDif { get; set; }
    }

    [Class(Table = "m_customercard_debtrestructuring", Name = "CCDebtRestructuring")]
    [Serializable]
    public class CCDebtRestructuring
    {
        public CCDebtRestructuring()
        {
        }

        [Id(0, Column = "ID_DebtRestructuring", Type = "int", Name = "ID_DebtRestructuring")]
        [Generator(1, Class = "identity")]
        public virtual int ID_DebtRestructuring { get; protected set; }

        [Property(Name = "ID_Deal", Column = "ID_Deal", Type = "int")]
        public virtual int ID_Deal { get; set; }

        [Property(Name = "PlanDate", Column = "PlanDate", Type = "DateTime")]
        public virtual DateTime PlanDate { get; set; }

        [Property(Name = "PlanAmount", Column = "PlanAmount", Type = "decimal")]
        public virtual decimal PlanAmount { get; set; }

        [Property(Name = "FactAmount", Column = "FactAmount", Type = "decimal")]
        public virtual decimal FactAmount { get; set; }

        [Property(Name = "FactDif", Column = "FactDif", Type = "decimal")]
        public virtual decimal FactDif { get; set; }
    }

    [Class(Table = "m_CustomerCard_Payment", Name = "CCPayment")]
    [Serializable]
    public class CCPayment
    {
        public CCPayment()
        {
        }

        [Id(0, Column = "ID_Payment", Type = "int", Name = "ID_Payment")]
        [Generator(1, Class = "identity")]
        public virtual int ID_Payment { get; protected set; }

        [Property(Name = "ID_Deal", Column = "ID_Deal", Type = "int")]
        public virtual int ID_Deal { get; set; }

        [Property(Name = "PlanAmount", Column = "PlanAmount", Type = "decimal")]
        public virtual decimal PlanAmount { get; set; }

        [Property(Name = "PlanDate", Column = "PlanDate", Type = "DateTime")]
        public virtual DateTime PlanDate { get; set; }

        [Property(Name = "FactAmount", Column = "FactAmount", Type = "decimal")]
        public virtual decimal FactAmount { get; set; }

        [Property(Name = "FactBody", Column = "FactBody", Type = "decimal")]
        public virtual decimal FactBody { get; set; }

        [Property(Name = "FactPercent", Column = "FactPercent", Type = "decimal")]
        public virtual decimal FactPercent { get; set; }

        [Property(Name = "ID_Sms", Column = "ID_Sms", Type = "int")]
        public virtual int ID_Sms { get; set; }

        //[ManyToOne(Class = "OrkarisSaas.Core.SaasSms", ClassType = typeof(SaasSms), Column = "ID_Sms", Insert = false, Update = false)]
        //public virtual SaasSms Sms { get; protected set; }

        [Property(Name = "FactDif", Column = "FactDif", Type = "decimal")]
        public virtual decimal FactDif { get; set; }

        [Property(Name = "FactSumDop", Column = "FactSumDop", Type = "decimal")]
        public virtual decimal FactSumDop { get; set; }

        [Property(Name = "PaymentBody", Column = "PaymentBody", Type = "decimal")]
        public virtual decimal PaymentBody { get; set; }

        [Property(Name = "PaymentPercent", Column = "PaymentPercent", Type = "decimal")]
        public virtual decimal PaymentPercent { get; set; }

        [Property(Name = "ID_User", Column = "ID_User", Type = "int")]
        public virtual int ID_User { get; set; }

        [Property(Name = "ID_AffiliateAddress", Column = "ID_AffiliateAddress", Type = "int")]
        public virtual int ID_AffiliateAddress { get; set; }
    }
}